//
//  main.m
//  小小通讯录
//  Created by qianfeng on 15/8/12.
//  Copyright (c) 2015年 qianfeng. All rights reserved.

#import <Foundation/Foundation.h>
#import "XYContactPerson.h"
#import "XYAnalysis.h"
#define PATH @"/Users/qianfeng/Desktop/qfile.txt"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        XYAnalysis * analysis = [[XYAnalysis alloc] init];
        [analysis analysisWithPath:PATH];
        
        XYAnalysis * person = [[XYAnalysis alloc] init];
        [person showAllInformation];
        
        int num;
        char name[50] = {};
        char * p = name;
        char address[100] = {};
        char * padd = address;
        char company[100] = {};
        char * pcom = company;
        char telephone[20] = {};
        char * ptele = telephone;
        
        while (1) {
            printf("\n1.显示所有人信息 2.按姓名查找联系人 3.添加联系人 4.删除联系人 5.编辑联系人 6.退出\n");
            printf("请选择相对应操作(输入数字):");
            scanf("%d",&num);
            while (*p) {
                *p = '\0';
                p++;
            }
            p = name;
            switch (num) {
                case 1:{
                    [analysis showAllInformation];
                    break;
                }
                case 2:{
                    printf("请输入联系人姓名:");
                    scanf("%s",p);
                    [analysis  findWithName:[NSString stringWithCString:p encoding:NSUTF8StringEncoding]];
                    break;
                }
                case 3:{
                    printf("请输入联系人姓名:");
                    scanf("%s",p);
                    printf(" 地址:");
                    scanf("%s",padd);
                    printf(" 公司:");
                    scanf("%s",pcom);
                    printf(" 电话:");
                    scanf("%s",ptele);
                    XYContactPerson * person = [[XYContactPerson alloc] init];
                    person.name = [NSString stringWithCString:p encoding:NSUTF8StringEncoding];
                    person.address = [NSString stringWithCString:padd encoding:NSUTF8StringEncoding];
                    person.company = [NSString stringWithCString:pcom encoding:NSUTF8StringEncoding];
                    person.telephone = [NSString stringWithCString:ptele encoding:NSUTF8StringEncoding];
                    [analysis  addWithPerson:person];
                    break;
                }
                case 4:{
                    printf("请输入删除对象姓名:");
                    scanf("%s",p);
                    [analysis  deleteWithName:[NSString stringWithCString:p encoding:NSUTF8StringEncoding]];
                    break;
                }
                case 5:{
                    printf("请输入需要编辑人的姓名:");
                    scanf("%s",p);
                    XYContactPerson * person1 = [analysis alterWithName:[NSString stringWithCString:p encoding:NSUTF8StringEncoding]];
                    if (person) {
                        printf("请输入新的电话号码:");
                        scanf("%s",ptele);
                        person1.telephone = [NSString stringWithCString:ptele encoding:NSUTF8StringEncoding];
                        [analysis addWithPerson:person1];
                    }
                    break;
                }
                case 6:{
                    exit(0);
                    break;
                }
                default:
                    break;
            }
        }
     }
    return 0;
}












